<?php if($pager->getNbResults() && ( $pager->getFirstPage() != $pager->getLastPage() )):?>
<?php 
	$width = 2;
	$total = $pager->getLastPage();
	$curPage = $pager->getPage();

	if( $curPage - $width > 0 && $curPage + $width <= $total ){
		$start = $curPage-$width;
	}else if( $curPage - $width < 1 && $curPage + $width <= $total ){
		$start = 1;
	}else if( $curPage - $width > 1 && $curPage + $width > $total ){
		$start = $curPage-$width-1;
	}else{
		$start = 1;
	}
			
?>
<div class="tootelehed">

	<?php for($i = $start; $i <= $pager->getLastPage() && ($i - $start+1) <= ($width * 2 + 1); ++$i):?>
	<div class="leht <?php echo $sf_request->getParameter('page',1) == $i  ? 'active superactive' : '' ?>">
		<p><a href="<?php echo LinkGen::getInstance(LinkGen::PRODUCT_GROUP)->link($category['id'], array('page' => $i)) ?>"><?php echo $i ?></a></p>
	</div>
	<?php endfor;?>
		<div class="clear"></div>
<script type="text/javascript">
	$('.leht').mouseover(function(){
	$(this).addClass('active');
	$('.leht').mouseleave(function(){
		if(!$(this).hasClass('superactive')){
			$(this).removeClass('active');
		}
	});
	});
</script>
</div>
<?php endif;?>